package com.etc.team2.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.team2.bean.Line;
import com.etc.team2.service.LineService;

public class getLineServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 用于获取用户指定线路信息
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		/*
		 * 获取用户键入的路线名，调用LineService()中getLine()方法；
		 * 若路线存在，则返回到lineforuser.jsp，表现给用户
		 * 若不存在，则返回到提示错误页面lineerror.jsp
		 */
		/*request.setCharacterEncoding("utf-8");
		String lineName=request.getParameter("username");
		Line line=new LineService().getLine(lineName);
		if(line!=null){
			request.setAttribute("line",line);
			request.getRequestDispatcher("lineforuser.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("lineerror.jsp").forward(request, response);
		}*/
		doPost(request,response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//request.setCharacterEncoding("utf-8");
		String lineName=new String(request.getParameter("username").getBytes("ISO-8859-1"),"utf-8");
		Line line=new LineService().getLine(lineName);
		if(line!=null){
			request.setAttribute("line",line );
			request.getRequestDispatcher("line.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("error.jsp").forward(request, response);
		}

	}

}
